package cn.zh.base.dto;

import cn.zh.base.util.MD5Utils;
import cn.zh.base.util.StrUtils;
import cn.zh.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.Date;


@Data
public class EmailRegisterDto {

    @NotNull(message = "邮箱不能为空")
    private String email;

    // uuid
    @NotNull(message = "uuid不能为空")
    private String imageCodeKey;

    // 图形验证码
    @NotNull(message = "图形验证码不能为空")
    private String imageCodeValue;

    // 手机号验证码
    @NotNull(message = "邮箱验证码不能为空")
    private String emailCode;

    // 密码
    @NotNull(message = "密码不能为空")
    private String password;
    // 确认密码
    @NotNull(message = "确认密码不能为空")
    private String passwordRepeat;


    public User getUser(){
        //盐值
        String salt = StrUtils.getComplexRandomString(32);
        /// todo 盐值 + 密码
        String pw = MD5Utils.encrypByMd5(salt + this.password);
        return User
                .builder()
                .createtime(new Date())
                .salt(salt)
                .password(pw)
                .state(1)
                .email(this.email)
                .username(this.email)
                .build();
    }

}
